static route_head *trk_head;
static route_head *rte_head;
+static int track_out_count;
static int route_out_count;
static int route_wpt_count;
static char *snupperopt;
static char *snuniqueopt;
-static char *ozi_wpt_header = "OziExplorer Waypoint File Version 1.1\n"
- "WGS 84\n"
- "Reserved 2\n"
- "Reserved 3\n";
-
-static char *ozi_trk_header = "OziExplorer Track Point File Version 2.1\n"
- "WGS 84\n"
- "Altitude is in Feet\n"
- "Reserved 3\n"
- "0,2,255,ComplimentsOfGPSBabel,0,0,2,8421376\n"
- "0\n";
-
-static char *ozi_route_header = "OziExplorer Route File Version 1.0\n"
- "WGS 84\n"
- "Reserved 1\n"
- "Reserved 2\n";
-
static
arglist_t ozi_args[] = {
{"snlen", &snlenopt, "Max synthesized shortname length",
{0, 0, 0, 0}
};
+gpsdata_type ozi_objective;
+
+static char *ozi_ofname = NULL;
+
+static void
+ozi_openfile(char *fname) {
+ char *c, *tmpname;
+ char *ozi_extensions[] = {0, "plt", "wpt", "rte"};
+ char buff[32];
+
+ /* if we're doing multi-track output, sequence the filenames like:
+ * mytrack.plt, mytrack-1.plt...
+ */
+
+ if ((track_out_count) && (ozi_objective == trkdata)) {
+ sprintf(buff, "-%d", track_out_count);
+ } else {
+ buff[0] = '\0';
+ }
+
+ /* allocate more than enough room for new filename */
+ tmpname = xcalloc(1, strlen(fname) +
+ strlen(buff) +
+ strlen(ozi_extensions[ozi_objective]) +
+ 2); /* . (dot) plus null term */
+
+ strcpy(tmpname, fname);
+
+ /* locate and remove file extension */
+ c = strrchr(tmpname, '.');
+
+ if (c)
+ *c = '\0';
+
+ /* append the -xx sequence number for tracks if needed */
+ strcat(tmpname + strlen(tmpname), buff);
+
+ strcat(tmpname, ".");
+
+ /* append the extension after the "." */
+ strcat(tmpname, ozi_extensions[ozi_objective]);
+
+ /* re-open file_out with the new filename */
+ if (file_out) {
+ fclose(file_out);
+ file_out = NULL;
+ }
+
+ file_out = xfopen(tmpname, "w", MYNAME);
+
+ xfree(tmpname);
+
+ return;
+}
+
static void
ozi_track_hdr(const route_head * rte)
{
- /* prologue at TOF only. */
- if (route_out_count == 0)
- fprintf(file_out, ozi_trk_header);
-
- route_out_count++;
+ static char *ozi_trk_header =
+ "OziExplorer Track Point File Version 2.1\n"
+ "WGS 84\n"
+ "Altitude is in Feet\n"
+ "Reserved 3\n"
+ "0,2,255,ComplimentsOfGPSBabel,0,0,2,8421376\n"
+ "0\n";
+
+ ozi_openfile(ozi_ofname);
+ fprintf(file_out, ozi_trk_header);
+
+ track_out_count++;
}
static void
static void
ozi_route_hdr(const route_head * rte)
{
+ static char *ozi_route_header =
+ "OziExplorer Route File Version 1.0\n"
+ "WGS 84\n"
+ "Reserved 1\n"
+ "Reserved 2\n";
+
/* prologue on 1st pass only */
if (route_out_count == 0) {
fprintf(file_out, ozi_route_header);
ozi_time,
waypointp->description ? waypointp->description : "");
-
}
static void
route_disp_all(ozi_route_hdr, ozi_route_tlr, ozi_route_disp);
}
-
static void
rd_init(const char *fname)
{
file_in = xfopen(fname, "r", MYNAME);
mkshort_handle = mkshort_new_handle();
-
- switch (global_opts.objective) {
- case trkdata:
- trk_head = route_head_alloc();
- track_add_head(trk_head);
- break;
- case rtedata:
- break;
- case wptdata:
- break;
- default:
- break;
-
- }
}
static void
rd_deinit(void)
{
fclose(file_in);
+ file_in = NULL;
mkshort_del_handle(mkshort_handle);
}
static void
wr_init(const char *fname)
{
- file_out = xfopen(fname, "w", MYNAME);
+
+ /* At this point, we have no idea whether we'll be writing waypoint,
+ * route, or tracks. So we'll hold off opening any files until
+ * we're actually ready to write.
+ */
+
+ ozi_ofname = (char *)fname;
+
mkshort_handle = mkshort_new_handle();
/* set mkshort options from the command line if applicable */
wr_deinit(void)
{
fclose(file_out);
+ file_out = NULL;
+ ozi_ofname = NULL;
+
mkshort_del_handle(mkshort_handle);
}
memset(buff, '\0', sizeof(buff));
fgets(buff, sizeof(buff), file_in);
+ /*
+ * this is particularly nasty. use the first line of the file
+ * to attempt to divine the data type we are parsing
+ */
+ if (linecount == 1) {
+ if (strstr(buff, "Track Point") != NULL) {
+ trk_head = route_head_alloc();
+ track_add_head(trk_head);
+ ozi_objective = trkdata;
+ } else
+ if (strstr(buff, "Route File") != NULL) {
+ ozi_objective = rtedata;
+ } else {
+ ozi_objective = wptdata;
+ }
+ }
if ((strlen(buff)) && (strstr(buff, ",") != NULL)) {
wpt_tmp = xcalloc(sizeof(*wpt_tmp), 1);
i = 0;
while (s) {
- switch (global_opts.objective) {
+ switch (ozi_objective) {
case trkdata:
ozi_parse_track(i, s, wpt_tmp);
break;
s = csv_lineparse(NULL, ",", "", linecount);
}
- switch (global_opts.objective) {
+ switch (ozi_objective) {
case trkdata:
if (linecount > 6) /* skipping over file header */
route_add_wpt(trk_head, wpt_tmp);
static void
data_write(void)
{
-
- switch (global_opts.objective) {
- case trkdata:
- ozi_track_pr();
- break;
- case rtedata:
- route_out_count = 0;
- ozi_route_pr();
- break;
- case wptdata:
+ static char *ozi_wpt_header =
+ "OziExplorer Waypoint File Version 1.1\n"
+ "WGS 84\n"
+ "Reserved 2\n"
+ "Reserved 3\n";
+
+ track_out_count = route_out_count = 0;
+
+ if (waypt_count()) {
+ ozi_objective = wptdata;
+ ozi_openfile(ozi_ofname);
fprintf(file_out, ozi_wpt_header);
waypt_disp_all(ozi_waypt_pr);
- break;
- default:
- break;
}
+
+ if (track_count()) {
+ ozi_objective = trkdata;
+ ozi_track_pr(); /* ozi_track_hdr handles filenames / file_out */
+ }
+
+ if (route_count()) {
+ ozi_objective = rtedata;
+ ozi_openfile(ozi_ofname); /* ozi routes go in one big file */
+ ozi_route_pr();
+ }
+
}
ff_vecs_t ozi_vecs = {
+++ /dev/null
-OziExplorer Waypoint File Version 1.1
-WGS 84
-Reserved 2
-Reserved 3
-1,GCEBB,35.972033,-87.134700,25569.00000,0,1,3,0,65535,Mountain Bike Heaven by susy1313,0,0,0,0,6,0,17
-2,GC1A37,36.090683,-86.679550,25569.00000,0,1,3,0,65535,The Troll by a182pilot & Family,0,0,0,0,6,0,17
-3,GC1C2B,35.996267,-86.620117,25569.00000,0,1,3,0,65535,Dive Bomber by JoGPS & family,0,0,0,0,6,0,17
-4,GC25A9,36.038483,-86.648617,25569.00000,0,1,3,0,65535,FOSTER by JoGPS & Family,0,0,0,0,6,0,17
-5,GC2723,36.112183,-86.741767,25569.00000,0,1,3,0,65535,Logan Lighthouse by JoGps & Family,0,0,0,0,6,0,17
-6,GC2B71,36.064083,-86.790517,25569.00000,0,1,3,0,65535,Ganier Cache by Susy1313,0,0,0,0,6,0,17
-7,GC309F,36.087767,-86.809733,25569.00000,0,1,3,0,65535,Shy's Hill by FireFighterEng33,0,0,0,0,6,0,17
-8,GC317A,36.057500,-86.892000,25569.00000,0,1,3,0,65535,GittyUp by JoGPS / Warner Parks,0,0,0,0,6,0,17
-9,GC317D,36.082800,-86.867283,25569.00000,0,1,3,0,65535,Inlighting by JoGPS / Warner Parks,0,0,0,0,6,0,17
--- /dev/null
+OziExplorer Waypoint File Version 1.1
+WGS 84
+Reserved 2
+Reserved 3
+1,GCEBB,35.972033,-87.134700,25569.00000,0,1,3,0,65535,Mountain Bike Heaven by susy1313,0,0,0,0,6,0,17
+2,GC1A37,36.090683,-86.679550,25569.00000,0,1,3,0,65535,The Troll by a182pilot & Family,0,0,0,0,6,0,17
+3,GC1C2B,35.996267,-86.620117,25569.00000,0,1,3,0,65535,Dive Bomber by JoGPS & family,0,0,0,0,6,0,17
+4,GC25A9,36.038483,-86.648617,25569.00000,0,1,3,0,65535,FOSTER by JoGPS & Family,0,0,0,0,6,0,17
+5,GC2723,36.112183,-86.741767,25569.00000,0,1,3,0,65535,Logan Lighthouse by JoGps & Family,0,0,0,0,6,0,17
+6,GC2B71,36.064083,-86.790517,25569.00000,0,1,3,0,65535,Ganier Cache by Susy1313,0,0,0,0,6,0,17
+7,GC309F,36.087767,-86.809733,25569.00000,0,1,3,0,65535,Shy's Hill by FireFighterEng33,0,0,0,0,6,0,17
+8,GC317A,36.057500,-86.892000,25569.00000,0,1,3,0,65535,GittyUp by JoGPS / Warner Parks,0,0,0,0,6,0,17
+9,GC317D,36.082800,-86.867283,25569.00000,0,1,3,0,65535,Inlighting by JoGPS / Warner Parks,0,0,0,0,6,0,17
compare ${TMPDIR}/tpg.mxf ${TMPDIR}/topo.mxf
# OZI (OziExplorer 1.1) file format
-rm -f ${TMPDIR}/oz.ozi ${TMPDIR}/ozi.ozi
-${PNAME} -i ozi -f reference/ozi.ozi -o ozi -F ${TMPDIR}/oz.ozi
-${PNAME} -i ozi -f ${TMPDIR}/oz.ozi -o ozi -F ${TMPDIR}/ozi.ozi
-compare ${TMPDIR}/ozi.ozi reference
+rm -f ${TMPDIR}/oz.wpt ${TMPDIR}/ozi.wpt
+${PNAME} -i ozi -f reference/ozi.wpt -o ozi -F ${TMPDIR}/oz.wpt
+${PNAME} -i ozi -f ${TMPDIR}/oz.wpt -o ozi -F ${TMPDIR}/ozi.wpt
+compare ${TMPDIR}/ozi.wpt reference
# Holux support is a little funky to test. Becuase it loses precision,
# if we convert it to another format, we lose accuracy (rounding) in the